/*
 *  $Id: HandCards.cs 881 2009-11-24 19:51:45Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima {
    /// <summary>
    /// Условие на карты в руках: игрок должен иметь не менее определенного числа карт
    /// </summary>
    public class HandCardsCondition: Condition {
        public readonly int Count;
        public readonly bool EnemyCards, WithSelf, Release;

        public static HandCardsCondition Own(int count) { return new HandCardsCondition(count, false, false, false); }
        public static HandCardsCondition OwnWithSelf(int count) { return new HandCardsCondition(count, false, true, false); }
        public static HandCardsCondition OwnRelease(int count) { return new HandCardsCondition(count, false, false, true); }
        public static HandCardsCondition OwnWithSelfAndRelease(int count) { return new HandCardsCondition(count, false, true, true); }
        public static HandCardsCondition Enemy(int count) { return new HandCardsCondition(count, true, false, false); }
        public static HandCardsCondition EnemyWithSelf(int count) { return new HandCardsCondition(count, true, true, false); }
        public static HandCardsCondition EnemyRelease(int count) { return new HandCardsCondition(count, true, false, true); }
        public static HandCardsCondition EnemyWithSelfAndRelease(int count) { return new HandCardsCondition(count, true, true, true); }

        private HandCardsCondition(int count, bool enemy, bool withSelf, bool release) {
            Count = count;
            EnemyCards = enemy;
            WithSelf = withSelf;
            Release = release;
        }

        public override bool Test(AbstractObject caster, Card card) {
            Player owner = caster.Owner;
            if (EnemyCards) owner = owner.Enemy;
            int count = owner.Hands.Count;
            if (!WithSelf) count++;
            return count > Count;
        }

        public override void DoCondition(AbstractObject caster, Card card) {
            if (Release) {
                Player owner = caster.Owner;
                if (EnemyCards) owner = owner.Enemy;
                owner.ReleaseCards(Count);
            }
        }

        private static readonly Languages.Phrase OwnLesser = new Languages.Phrase("condition.handcards.own");
        private static readonly Languages.Phrase EnemyLesser = new Languages.Phrase("condition.handcards.enemy");

        public override Languages.Phrase Notice {
            get { return EnemyCards ? EnemyLesser : OwnLesser; }
        }
        public override string NoticeText {
            get { return Notice.GetText(Count); }
        }
    }
}